package com.hmdp.config;

import com.hmdp.utils.LoginInterceptor;
import com.hmdp.utils.RefreshTokenInterceptor;
import lombok.RequiredArgsConstructor;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * ClassName: MvcConfig
 * Package:
 * Description:
 *
 * @Author:xiaohei
 * @Create 2024/5/29 19:07
 * Version 1.0
 */
@Configuration
@RequiredArgsConstructor
//默认是按照添加顺序执行   可以用order指定优先级   数字越小越先执行
public class MvcConfig implements WebMvcConfigurer {

    private final StringRedisTemplate stringRedisTemplate;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //登录拦截器
        registry.addInterceptor(new LoginInterceptor()).excludePathPatterns(
                "/voucher/**",
                "/upload/**",    //TODO 基于测试放行了  后续需要去掉
                "/shop-type/**",
                "/shop/**",
                "/blog/hot",
                "/user/code",
                "/user/login"
        ).order(1);
        //token刷新拦截器
        registry.addInterceptor(new RefreshTokenInterceptor(stringRedisTemplate)).addPathPatterns("/**").order(0);
    }
}
